package com.sky.controller.user;

import com.sky.entity.Dish;
import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.SetMealService;
import com.sky.vo.DishVO;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "套餐相关接口")
@RestController("userSetMealController")
@RequestMapping("/user/setmeal")
public class SetMealController {
    @Autowired
    private SetMealService setMealService;

    /**
     * 根据分类id查询套餐
     * @param categoryId
     * @return
     */
    @ApiOperation("根据分类id查询套餐")
    @GetMapping("/list")
    @Cacheable(cacheNames = "setmealCache", key = "#categoryId")
    public Result<List<Setmeal>> getSetMealByCategoryId(@RequestParam Long categoryId) {
        List<Setmeal> setmealList = setMealService.getSetMealByCategoryId(categoryId);
        return Result.success(setmealList);
    }

    /**
     * 根据套餐id查询菜品
     * @param id
     * @return
     */
    @ApiOperation("根据套餐id查询菜品")
    @GetMapping("/dish/{id}")
    public Result<List<DishVO>> getDishBySetMealId(@PathVariable Long id) {
        List<DishVO> dishVOList = setMealService.getDishBySetMealId(id);
        return Result.success(dishVOList);
    }
}
